package com.study.project.config.exception;

public class Response<T> {
    private String code = "000";
    private String msg = "ok";
    private T data;

    protected Response() {}

    public static <T> Response<T> error(ErrorCode error) {
        return (new Response()).setCode(error.getCode()).setMsg(error.getMsg());
    }

    public static <T> Response<T> error(String code, String msg) {
        return (new Response()).setCode(code).setMsg(msg);
    }

    public static <T> Response<T> success() {
        return (new Response<T>()).setCode("000").setMsg("ok");
    }

    public static <T> Response<T> success(T data) {
        return (new Response<T>()).setCode("000").setMsg("ok").setData(data);
    }

    public static <T> Response<T> success200(T data) {
        return (new Response<T>()).setCode("200").setMsg("ok").setData(data);
    }

    public static <T> Response<T> success(String code, String msg, T data) {
        return (new Response<T>()).setCode(code).setMsg(msg).setData(data);
    }

    public String getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public Response<T> setCode(final String code) {
        this.code = code;
        return this;
    }

    public Response<T> setMsg(final String msg) {
        this.msg = msg;
        return this;
    }

    public Response<T> setData(final T data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return "Response(code=" + this.getCode() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")";
    }
}